﻿<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>邯郸市公安局峰峰矿区分局-登陆</title>
    <link rel="stylesheet" href="css/reset.css">
    <link rel="stylesheet" href="css/login.css">
    <script src="./libs/jquery-1.9.1.min.js"></script>
    <script src="./libs/jquery.cookie.js"></script>
    <script src="./js/config.js"></script>
    <!-- <script src="../config.js"></script> -->


    <!-- <script src="./libs/jquery.xdomainrequest.min.js"></script> -->
</head>

<body>
    <div class="header-box">
        <div class="header-insert-box">
            <div class="logo-box"></div>
            <div class="function-box">
                    <a href="../app/index.html" target="_Blank"><div class="download-center">网站首页</div></a>
            </div>

        </div>
    </div>

    <div class="content-box">
        <img src="./images/wujing.png" class="wujing" alt="">

        <div class="login-box">
            <h1 class="header-title">登陆管理系统</h1>

            <div class="user-group">
                <span class="user-icon"></span>
                <span class="line"></span>
                <input type="text" placeholder="用户名" class="user-input">
            </div>

            <div class="password-group">
                <span class="password-icon"></span>
                <span class="line"></span>
                <input type="password" placeholder="请输入您的密码" class="password-input">
            </div>

            <div class="forget-pass-box">
                <div class="remember-pass">
                    <input type="checkbox" name="layout" id="c2" class="check-box">
                    <label for="c2">记住密码</label>
                </div>
                <div class="remember-pass">
                    <input type="checkbox" name="layout" id="c3" class="check-boxsuper">
                    <label for="c3">超级管理登陆</label>
                </div>
            </div>


            <div class="login-btn" can-click="true">
                登陆
            </div>

        </div>

    </div>


    <div class="footer-box">
        <p class="text-1">主办：邯郸市公安局峰峰矿区分局 </p>
        <p class="text-2">Copyright © 2018-2022 All Rights Reserved</p>
    </div>
</body>
<script>
    $(function () {
        // 保持中间大小
        var height = $(window).height() - 314;
        if (height < 400) {
            height = 400;
        }
        $('.content-box').css('height', height);
        setInterval(function () {
            var height = $(window).height() - 314;
            if (height < 400) {
                height = 400;
            }
            $('.content-box').css('height', height);
        }, 1200);



        // 用户是否记住密码
        if ($.cookie('gn_userRemober')) {
            var user_obj = $.parseJSON($.cookie('gn_userRemober'));
            $('.user-input').val(user_obj['user']);
            $('.password-input').val(user_obj['pass']);

            $('.check-box').attr('checked','true')
        }

        $('.login-btn[can-click="true"]').on('click', function () {
            var _this = $(this);
            if (_this.attr('can-click') == 'true') {
                _this.attr('can-click', 'false');
                var user_name = $('.user-input').val();
                var user_password = $('.password-input').val();
                if (user_name && user_password) {
                    //判断是不是超级管理员
                    if ($('.check-boxsuper').is(':checked')) {
                        $.ajax({
                            type: 'POST',
                            url: $.webConfig.apiUrl + 'admin/login',
                            data: {
                                user: user_name,
                                pass: user_password
                            },
                            cache: false,
                            dataType: 'json',
                            success: function (data) {
                                console.log(data);
                                if (data['return_code'] == 1) {
                                    data['return_body'].isSuperAdministrator = 1;
                                    $.cookie('gn_userObj', JSON.stringify(data[
                                        'return_body']), {
                                        expires: 7,
                                        path: '/'
                                    });


                                    // 用户是否记住密码
                                    if ($('.check-box').is(':checked')) {
                                        var user_obj = {
                                            user: user_name,
                                            pass: user_password
                                        };
                                        $.cookie('gn_userRemober', JSON.stringify(user_obj), {
                                            expires: 7,
                                            path: '/'
                                        });
                                    } else {
                                        $.cookie('gn_userRemober', null, {
                                            expires: -1,
                                            path: '/'
                                        });
                                    }
                                    alert('登陆成功');
                                    window.location.href = '/admin/';
                                } else {
                                    alert(data['return_msg']);
                                    _this.attr('can-click', 'true');
                                }
                            },
                            error: function (err) {
                                console.log(err);
                                alert('服务器出小差咯...');
                            }
                        })


                    } else {

                        $.ajax({
                            type: 'POST',
                            url: $.webConfig.apiUrl + 'xsuser/loginxs',
                            data: {
                                username: user_name,
                                password: user_password
                            },
                            cache: false,
                            dataType: 'json',
                            success: function (data) {
                                if (data['return_code'] == 1) {
                                    data['return_body'].isSuperAdministrator = 2;
                                    $.cookie('gn_userObj', JSON.stringify(data[
                                        'return_body']), {
                                        expires: 7,
                                        path: '/'
                                    });
                                    // 用户是否记住密码
                                    if ($('.check-box').is(':checked')) {
                                        var user_obj = {
                                            user: user_name,
                                            pass: user_password
                                        };
                                        $.cookie('gn_userRemober', JSON.stringify(user_obj), {
                                            expires: 7,
                                            path: '/'
                                        });
                                    } else {
                                        $.cookie('gn_userRemober', null, {
                                            expires: -1,
                                            path: '/'
                                        });
                                    }
                                    alert('登陆成功');
                                    window.location.href = '/admin/';
                                } else {
                                    alert(data['return_msg']);
                                    _this.attr('can-click', 'true');
                                }
                            },
                            error: function (err) {
                                alert('服务器出小差咯...');
                            }
                        })
                    }


                } else {
                    alert('用户名密码格式错误');
                }

            } else {
                _this.attr('can-click', 'true');
            };
        })
    });
</script>

</html>